From: kaf24@firebug.cl.cam.ac.uk Date: Thu, 25 May 2006 13:29:21 +0000 (+0100) Subject: [NET] front: Use netif_carrier to model backend-connection state. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~16025^2~20 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=4cebc4c9b20597d96855f41d39047cbda78335a4;p=xen.git [NET] front: Use netif_carrier to model backend-connection state. The tristate backend_state really only needs to be a boolean. In fact other virtualisation network drivers such as the s390 already model this using netif_carrier_*. So by converting backend_state over to the net carrier flag we can tap into existing infrastructure rather than creating new ones. Signed-off-by: Herbert Xu --- diff --git a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c index 02f241c0b7..f4f68a2e23 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c @@ -89,12 +89,6 @@ struct netfront_info { unsigned int handle; unsigned int evtchn, irq; - /* What is the status of our connection to the remote backend? */ -#define BEST_CLOSED 0 -#define BEST_DISCONNECTED 1 -#define BEST_CONNECTED 2 - unsigned int backend_state; - /* Receive-ring batched refills. */ #define RX_MIN_TARGET 8 #define RX_DFL_MIN_TARGET 64 @@ -144,14 +138,6 @@ static inline unsigned short get_id_from_freelist(struct sk_buff **list) return id; } -#ifdef DEBUG -static const char *be_state_name[] = { - [BEST_CLOSED] = "closed", - [BEST_DISCONNECTED] = "disconnected", - [BEST_CONNECTED] = "connected", -}; -#endif - #define DPRINTK(fmt, args...) pr_debug("netfront (%s:%d) " fmt, \ __FUNCTION__, __LINE__, ##args) #define IPRINTK(fmt, args...) \ @@ -342,7 +328,6 @@ static int setup_device(struct xenbus_device *dev, struct netfront_info *info) } memset(txs, 0, PAGE_SIZE); memset(rxs, 0, PAGE_SIZE); - info->backend_state = BEST_DISCONNECTED; SHARED_RING_INIT(txs); FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE); @@ -465,7 +450,7 @@ static void network_tx_buf_gc(struct net_device *dev) struct netfront_info *np = netdev_priv(dev); struct sk_buff *skb; - if (np->backend_state != BEST_CONNECTED) + if (unlikely(!netif_carrier_ok(dev))) return; do { @@ -527,7 +512,7 @@ static void network_alloc_rx_buffers(struct net_device *dev) struct xen_memory_reservation reservation; grant_ref_t ref; - if (unlikely(np->backend_state != BEST_CONNECTED)) + if (unlikely(!netif_carrier_ok(dev))) return; /* @@ -662,7 +647,7 @@ static int network_start_xmit(struct sk_buff *skb, struct net_device *dev) spin_lock_irq(&np->tx_lock); - if (np->backend_state != BEST_CONNECTED) { + if (unlikely(!netif_carrier_ok(dev))) { spin_unlock_irq(&np->tx_lock); goto drop; } @@ -748,7 +733,7 @@ static int netif_poll(struct net_device *dev, int *pbudget) spin_lock(&np->rx_lock); - if (np->backend_state != BEST_CONNECTED) { + if (unlikely(!netif_carrier_ok(dev))) { spin_unlock(&np->rx_lock); return 0; } @@ -1041,7 +1026,7 @@ static void network_connect(struct net_device *dev) * domain a kick because we've probably just requeued some * packets. */ - np->backend_state = BEST_CONNECTED; + netif_carrier_on(dev); notify_remote_via_irq(np->irq); network_tx_buf_gc(dev); @@ -1055,7 +1040,7 @@ static void show_device(struct netfront_info *np) if (np) { IPRINTK("\n", np->handle, - be_state_name[np->backend_state], + netif_carrier_ok(np->netdev) ? "on" : "off", netif_running(np->netdev) ? "open" : "closed", np->evtchn, np->tx, @@ -1241,10 +1226,11 @@ static struct net_device * __devinit create_netdev(int handle, } np = netdev_priv(netdev); - np->backend_state = BEST_CLOSED; np->handle = handle; np->xbdev = dev; + netif_carrier_off(netdev); + spin_lock_init(&np->tx_lock); spin_lock_init(&np->rx_lock); @@ -1392,7 +1378,7 @@ static void netif_disconnect_backend(struct netfront_info *info) /* Stop old i/f to prevent errors whilst we rebuild the state. */ spin_lock_irq(&info->tx_lock); spin_lock(&info->rx_lock); - info->backend_state = BEST_DISCONNECTED; + netif_carrier_off(info->netdev); spin_unlock(&info->rx_lock); spin_unlock_irq(&info->tx_lock);